package com.atguigu.processor;

import com.atguigu.pojo.Car;
import com.atguigu.pojo.User;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    //bean初始化之前
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.err.println("bean初始化之前"+bean);
        System.err.println("bean初始化之前"+beanName);
        return bean;
    }
    //bean初始化之后
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if("user30".equals(beanName)){
            System.err.println("改变bean");
            User user=(User) bean;
            user.setCar(new Car("12121212","拉萨拉萨拉力赛"));
            return user;
        }
        return null;
    }
}
